import json
import requests

url = "https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items?os=ios&start=0&count=8&loc_id=108288&_=1546931422844"
headers = {
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1","Referer": "https://m.douban.com/movie/"
}
response = requests.get(url,headers=headers,timeout=5)
json_str = response.content.decode()
# 去掉参数 &callback=jsonp1
#print(json_str)
ret = json.loads(json_str)
# indent 空格
# ensure_ascii = False  让中文显示中文
jsonToStr = json.dumps(ret, ensure_ascii=False, indent=2)
with open("doubanMovie.json", "w", encoding="utf-8") as f:
    f.write(jsonToStr)
print(ret)